package com.yhn.init.config.sa_token;

import cn.dev33.satoken.stp.StpInterface;
import com.yhn.init.mapper.RoleMenuMapper;
import com.yhn.init.mapper.UserMapper;
import com.yhn.init.model.entity.User;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 实现Satoken鉴权
 *
 * @author yhnyhn123
 */
@Component
public class StpInterfaceImpl implements StpInterface {
    @Resource
    private RoleMenuMapper roleMenuMapper;
    @Resource
    private UserMapper userMapper;

    /**
     * 返回一个用户所拥有的权限集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<String> list = new ArrayList<>();
        User user = userMapper.selectById((Serializable) loginId);
        if (user.getRoleId() == 1) {
            list.add("root");
            return list;
        }
        return roleMenuMapper.getMenuByUserId(loginId);
    }


    /**
     * 返回一个用户所拥有的角色标识集合
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginKey) {
        return new ArrayList<>();
    }

}
